package com.jomoo.common.tools;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateTools
{
	public static Date getStartTime() 
	{  
    	SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); 
    	String nowDate = null;
        Calendar todayStart = Calendar.getInstance(); 
        try
		{
        	todayStart.add(Calendar.MONTH, 0);
        	todayStart.set(Calendar.DAY_OF_MONTH, 1);
        	nowDate = sf.format(todayStart.getTime());
			todayStart.setTime(sf.parse(nowDate));
		}
		catch (ParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return todayStart.getTime();  
    }  
  
	public static Date getEndTime() 
    {  
    	SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); 
    	String nowDate = null;
        Calendar todayEnd = Calendar.getInstance();  
        try
		{
        	todayEnd.add(Calendar.MONTH, 1);
        	todayEnd.set(Calendar.DAY_OF_MONTH, 0);
        	nowDate = sf.format(todayEnd.getTime());
        	todayEnd.setTime(sf.parse(nowDate));
		}
		catch (ParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
        return todayEnd.getTime();  
    }  
	
	public static Date getAfterDay(String dayTime) throws Exception
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(dayTime);
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);

		// 获取指定时间的日
		int day = cal.get(Calendar.DATE);

		// 在指定时间的基础上加1天
		cal.set(Calendar.DATE, day + 1);

		// 返回加1天后的日期
		return cal.getTime();
	}
	
	public static Date getStartDate()
	{
		Date date = new Date(); 
    	SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); 
    	String nowDate = sf.format(date);
        Calendar todayStart = Calendar.getInstance(); 
        try
		{
			todayStart.setTime(sf.parse(nowDate));
		}
		catch (ParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return todayStart.getTime();  
	}
	
	public static Date getEndDate()
	{
		Date date = new Date(); 
    	SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); 
    	String nowDate = sf.format(date);
        Calendar todayEnd = Calendar.getInstance();  
        try
		{
			todayEnd.setTime(sf.parse(nowDate));
			todayEnd.add(Calendar.DAY_OF_YEAR, +1);
		}
		catch (ParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
        return todayEnd.getTime();  
	}
}
